package mantaince;

/**
 * User: Yahor Kastsialei
 * Date: 11/6/13
 * Time: 2:21 PM
 */
public class SnowRescueService {
    WeatherForecastService weatherForecastService;
    MunicipalServices municipalServices;
    PressService pressService;

    public SnowRescueService(WeatherForecastService weatherForecastService, MunicipalServices municipalServices, PressService pressService) {
        this.weatherForecastService = weatherForecastService;
        this.municipalServices = municipalServices;
        this.pressService = pressService;
    }

    public void checkForecastAndRescue() {
        int temperature = weatherForecastService.getAverageTemperatureInCelsius();
        int snowLevel = weatherForecastService.getSnowFallHeightInMM();
        if (temperature < 0 && temperature >= -10) {
            municipalServices.sendSander();
        }
        if (snowLevel >= 3) {
            try {
                municipalServices.sendSnowplow();
            } catch (SnowplowMalfunctioningException exception) {
                municipalServices.sendSnowplow();
            }
        }
        if (snowLevel >= 5) {
            try {
                municipalServices.sendSnowplow();
            } catch (SnowplowMalfunctioningException exception) {
                municipalServices.sendSnowplow();
            }
        }
        if (temperature < -10 && snowLevel >= 10) {
            try {
                municipalServices.sendSnowplow();
            } catch (SnowplowMalfunctioningException exception) {
                municipalServices.sendSnowplow();
            }
            municipalServices.sendSander();
            pressService.sendWeatherAlert();
        }
    }

}